import { request } from '@pkg/request/src';
import {toTreeList} from '@pkg/utils';

export enum Api {
  list = '/shop/type/all',
  add = '/shop/type/save',
  update = '/shop/type/update',
  remove = '/shop/type/remove',
  setState = '/shop/type/setState'
}

export const list = () => {
  return request.get({url: Api.list}, {errorMessageMode: 'none', successMessageMode: 'none'}).then((data) => {
    const opt = {primaryKey: 'typeId', title: 'typeName'};
    return toTreeList(data, opt, '0');
  });
}

export const add = (params) => {
  return request.post({url: Api.add, params: params}, {errorMessageMode: 'none'});
}

export const update = (params) =>
    request.post({url: Api.update, params: params}, {errorMessageMode: 'none'});

export const remove = (ids: string) =>
    request.post({url: Api.remove, params: {ids: ids}}, {errorMessageMode: 'none'});
